Docker: Docker Cheatsheet

Last update: 10/19/2023, 10:57:44 AM

Install on Ubuntu

https://docs.docker.com/engine/install/ubuntu/

Handy commands

Execute shell docker exec -it <container-name> sh

Remove unused data volumes docker volume prune. Prune the rest: docker system prune.

Display IP info of running containers: docker network inspect bridge

Compose snags

From reddit: https://www.reddit.com/r/docker/comments/gac0rd/conflict_the_container_name_is_already_in_use_by/

When we use docker-compose, it has a project name which defaults to the current directory name. For example, if you ran the docker-compose.yml inside a folder/directory called project1, now the container is created for project1 and joins the automatically created project1_default docker network.

Since you have moved them to another directory called docker, running the compose file will mean that you are trying to create the container for the project name docker that joins the automatically created docker_default docker network. As they are essential different projects, you will run into the naming conflict.

One workaround would be running the docker-compose command with the -p flag that overrides the default project name which is the current directory - docker. If the original directory was old_dir for example, your command would look like:

docker-compose -p old_dir up -d

However, it still means you need to use the old directory in the command even though you have moved them. If you truly wish to run docker-compose without the -p workaround, it's best to to remove the old containers and run docker-compose as usual.

If you had bind mount or use volume to persist data for the containers, I don't see any reason to feel attached to the current running containers since we should approach containers in a stateless manner.